package com.hefei.acl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hefei.acl.entity.User;
import com.hefei.acl.mapper.UserMapper;
import com.hefei.acl.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hefei.acl.vo.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author caizhengjun
 * @since 2021-03-05
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Long countUser() {
        return this.userMapper.countUser();
    }

    @Override
    public String login(LoginVo loginVo) {

        String username = loginVo.getUsername();
        String password = loginVo.getPassword();

        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username)
                .eq("password", password);

        User user = this.userMapper.selectOne(queryWrapper);
        //Token TODO
        if (!StringUtils.isEmpty(user)) {
            return "token";
        } else {
            return null;
        }
    }
}
